package org.example.controller;


import org.example.model.Book;
import org.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/addBook")
    public String addBook() {
        Book book = new Book("西游记",1,20.99,"四大名著");
        ArrayList<Book> books = new ArrayList<Book>();
        books.add(book);
        int i = bookService.addBook(books);
        return "success"; //自定进行视图解析，success.jsp
    }

    @GetMapping(value = "/addBook4")
    @ResponseBody
    public Book addBook4(int btype,String name) {
        System.out.println(name);
        System.out.println(btype);
        Book book = new Book("西游记",1,20.99,"四大名著");

        return book;
    }

    @PostMapping(value = "/addBook1")
    @ResponseBody
    public Book addBook1(int btype,String name) {
        System.out.println(name);
        System.out.println(btype);
        Book book = new Book("西游记",1,20.99,"四大名著");
        ArrayList<Book> books = new ArrayList<Book>();
        books.add(book);
        int i = bookService.addBook(books);
        return book;
    }



    @PostMapping(value = "/addBook2")
    @ResponseBody
    public String addBook2(Book book1) {
        System.out.println(book1.getBtype());
        System.out.println(book1.getBname());
        Book book = new Book("西游记",1,20.99,"四大名著");
        ArrayList<Book> books = new ArrayList<Book>();
        books.add(book);
        int i = bookService.addBook(books);
        return "success";
    }

    @PostMapping(value = "/addBook3")
    @ResponseBody
    public Book addBook3(@RequestBody Book book1) {
        System.out.println(book1.getBtype());
        System.out.println(book1.getBname());
        Book book = new Book("西游记",1,20.99,"四大名著");

        return book;
    }

}
